home *** CD-ROM | disk | FTP | other *** search
/ SGI Hot Mix 17 / Hot Mix 17.iso / HM17_SGI / research / examples / misc / wexmast / worldrot.pro < prev    next >
Text File  |  1997-07-08  |  15KB  |  414 lines

  1. ; $Id: worldrot.pro,v 1.6 1997/01/15 04:29:15 ali Exp $
  2. ;
  3. ; Copyright (c) 1993-1997, Research Systems, Inc.  All rights reserved.
  4. ;       Unauthorized reproduction prohibited.
  5.  
  6. PRO WORLDROT_EVENT, EVENT
  7. ;THIS IS THE WORLDROT EVENT HANDLER
  8.  
  9. ;COMMON BLOCK
  10. ;
  11.  
  12. common worldr_block,projection,minlon,maxlon,minlat,maxlat,viewlat,width,$
  13.                    height,numframes,cna,dne,theproj,base,names,help,$
  14.            rotangle,message,adjust,display,concol,gridcol,$
  15.            drawcon,nocon,drawgrid,nogrid,wlevel,latsamp,lonsamp,$
  16.            bilinear,nointerp,grid,con,bilin
  17.  
  18. ; This IF THEN ELSE handles clicking on the exclusive menu of projections.
  19. ; The variable 'projection' was set with the 'buttons' keyword when the 
  20. ; exclusive menu of projections was created.
  21. ; The WHERE expression sets the value of 'projflag' to 1 if one of the 
  22. ; exclusive buttons is clicked on.  The variable 'projselection' will also
  23. ; hold the index of the button touched.
  24.  
  25. projselection = WHERE(projection EQ event.id, projflag)
  26.  
  27. IF (projflag NE 0) THEN BEGIN
  28.   theproj = projselection[0]
  29.  
  30. ENDIF ELSE BEGIN
  31.  
  32. ;If something other than a exclusive button has been touched, manage the event
  33. ;with this CASE statement.
  34.  
  35. WIDGET_CONTROL, event.id, GET_UVALUE = eventval 
  36. CASE eventval OF
  37.     "CREATE":BEGIN
  38.  
  39.         ;If Xinteranimate is already going, DON'T DO THIS:
  40.         IF (XREGISTERED("XInterAnimate") NE 0) THEN RETURN
  41.  
  42.         ;If the Create New Animation Button is pressed, 
  43.         ;read the values of all of the widgets from the tool.
  44.         ;Projection number is already in THEPROJ.
  45.  
  46.         ;Read the Info about Image fields:
  47.         WIDGET_CONTROL, minlon, GET_VALUE    = lon1
  48.                 WIDGET_CONTROL, maxlon, GET_VALUE    = lon2
  49.                 WIDGET_CONTROL, minlat, GET_VALUE    = lat1
  50.                 WIDGET_CONTROL, maxlat, GET_VALUE    = lat2
  51.  
  52.         ;Read the Latitude to be Centered slider:
  53.                 WIDGET_CONTROL, viewlat, GET_VALUE   = vlat
  54.     
  55.         ;The Rotation of North slider:
  56.         WIDGET_CONTROL, rotangle,GET_VALUE   = rot
  57.  
  58.         ;The size of the animation window:
  59.                 WIDGET_CONTROL, width, GET_VALUE     = wide
  60.                 WIDGET_CONTROL, height, GET_VALUE    = high
  61.         
  62.         ;The number of frames to be generated:
  63.                 WIDGET_CONTROL, numframes, GET_VALUE = nframes
  64.  
  65.         ;The grid and continent colors:
  66.         WIDGET_CONTROL, concol, GET_VALUE    = concolor
  67.         WIDGET_CONTROL, gridcol, GET_VALUE   = gridcolor
  68.  
  69.         ;The Latitude and Longitude sampling parameters:
  70.         WIDGET_CONTROL, latsamp, GET_VALUE   = lts
  71.         WIDGET_CONTROL, lonsamp, GET_VALUE   = lns
  72.         
  73.         ;These numbers get returned as arrays. Turn them into scalars:
  74.         nframes = nframes[0]
  75.         high = high[0]
  76.         wide = wide[0]
  77.         concolor = concolor[0]
  78.         gridcolor = gridcolor[0]
  79.         lon1=lon1[0]
  80.         lon2=lon2[0]
  81.         lat1=lat1[0]
  82.         lat2=lat2[0]
  83.         vlat=vlat[0]
  84.         rot=rot[0]
  85.         lts=lts[0]
  86.         lns=lns[0]
  87.  
  88.         ;Make the Worldrot Widget insensitive.
  89.         WIDGET_CONTROL, base, SENSITIVE=0
  90.  
  91.         ;Convert THEPROJ to correct argument to proj keyword.
  92.         ;CONVECT maps the projection menu into correct proj keyvalue:
  93.         convect = [6,8,5,4,9,10,2,14,1]
  94.         p = convect[theproj]
  95.  
  96.         ;Make the title for XinterAnimate window:
  97.         title = 'Rotating ' + names[theproj] + ' Projection'
  98.  
  99.         ;Make Animation Frames:
  100.             XINTERANIMATE, SET = [wide, high, nframes], $
  101.                      TITLE=title, GROUP = event.top, $
  102.                      /SHOWLOAD
  103.         step = 360./nframes
  104.     
  105.             FOR i=0,nframes-1 DO BEGIN
  106.             ;Make the 'Frame n of x created.' message:
  107.                     mess =     'Frame '+ STRING(i+1, format='(I0)') + $
  108.                 ' of ' + STRING(nframes, FORMAT='(I0)')+' created.'
  109.  
  110.             ;Set up the map projection:
  111.             MAP_SET, vlat, i*step-180, rot, PROJ=p
  112.  
  113.  
  114.             ;Warp the image and return it as 'img':
  115.             img = MAP_IMAGE(ROUTINE_NAMES('IM', FETCH = wlevel), $
  116.                     startx, starty, LATSAMP=lts, $
  117.                     LONSAMP=lns, LONMIN=lon1, LONMAX=lon2,$
  118.                     LATMIN=lat1, LATMAX=lat2, $
  119.                     BILINEAR = bilin)
  120.  
  121.             ;Display the image on the map:
  122.             TV, img, startx, starty
  123.  
  124.             ;Draw the continents and gridlines if we're supposed to:
  125.             IF (grid EQ 1) THEN MAP_GRID, COLOR = gridcolor
  126.             IF (con EQ 1)  THEN MAP_CONTINENTS, COLOR = concolor
  127.  
  128.             ;Put the message in the message window:
  129.             WIDGET_CONTROL, message, SET_VALUE = mess
  130.  
  131.             ;Put the new frame into the Xinteranimate[B tool:
  132.                     XINTERANIMATE, FRAME = i, WINDOW = !D.WINDOW
  133.  
  134.                 END
  135.  
  136.             
  137.         ;Call the Animation Tool & display new message
  138.         WIDGET_CONTROL, message, SET_VALUE=display
  139.         XINTERANIMATE, 80, GROUP = event.top 
  140.         
  141.         ;Resensitize the Worldrot Widget
  142.  
  143.         WIDGET_CONTROL, base, /SENSITIVE
  144.         WIDGET_CONTROL, message, SET_VALUE = adjust
  145.         
  146.         END ;Create case
  147.  
  148.     "DRAWGRID": grid = 1    ;Turn grid drawing ON.
  149.       "NOGRID": grid = 0    ;Turn grid drawing OFF.
  150.  
  151.      "DRAWCON": con = 1        ;Turn continent drawing ON.
  152.        "NOCON": con = 0        ;Turn continent drawing OFF.
  153.  
  154.     "BILINEAR": bilin = 1    ;Turn bilinear interpolation ON.
  155.     "NOINTERP": bilin = 0    ;Turn bilinear interpolation OFF.
  156.  
  157.     "HELP": BEGIN 
  158.         ;If HELP is pressed, display the help file.
  159.         XDISPLAYFILE, FILEPATH('worldrthelp.txt', $
  160.                     SUBDIR = ['examples', 'misc', 'wexmast']), $
  161.             GROUP=event.top, TITLE='World Rotation Tool Help'
  162.         END ;Help case
  163.  
  164.     "DONE": WIDGET_CONTROL, event.top, /DESTROY    ;If 'Done' is pressed,
  165.                             ;destroy all widgets
  166.                             ;and return to IDL.
  167.  
  168.       ELSE: donothing=0    ;If nothing is pressed, don't do anything.
  169.  
  170.     ENDCASE
  171.  
  172. ENDELSE ;(projflag NE 0)
  173.  
  174. END
  175.  
  176.  
  177.  
  178. ; !!! MAKE THE ACTUAL WIDGETS !!!
  179.  
  180. PRO worldrot, im, GROUP = GROUP
  181. ; 'im' is the image that the user wants to warp.  It is assumed to be
  182. ;  already properly scaled for the display 
  183.  
  184. ; COMMON BLOCK
  185. COMMON worldr_block,projection,minlon,maxlon,minlat,maxlat,viewlat,width,$
  186.                    height,numframes,cna,dne,theproj,base,names,help,$
  187.            rotangle,message,adjust,display,concol,gridcol,$
  188.            drawcon,nocon,drawgrid,nogrid,wlevel,latsamp,lonsamp,$
  189.            bilinear,nointerp,con,grid,bilin
  190.  
  191. ; Only one copy of WORLDROT can run at a time due to the COMMON block.
  192. ; Check for other copies and do nothing if WORLDROT is already running:
  193.  
  194. IF(XRegistered("worldrot") NE 0) THEN RETURN
  195.  
  196. wlevel = ROUTINE_NAMES(/LEVEL)        ;Current level
  197.  
  198. ;Find the dimensions of the image:
  199. imsize=SIZE(im)
  200.  
  201. ;MAIN WIDGET BASE
  202. base = WIDGET_BASE(TITLE='World Rotation Tool', /ROW)
  203.  
  204. ;WORLD ROTATION TOOL HAS 3 MAIN COLUMNS
  205. lcol = WIDGET_BASE(base, /FRAME, /COLUMN)    ;Left column.
  206. mcol = WIDGET_BASE(base, /FRAME, /COLUMN)    ;Middle column.
  207. rcol = WIDGET_BASE(base, /FRAME, /COLUMN)    ;Right column.
  208.  
  209. ;LEFT COLUMN IS THE EXCLUSIVE MENU OF PROJECTION TYPES, BUTTONS, AND OPTIONS
  210. lpad = WIDGET_BASE(lcol, /FRAME, /ROW)
  211. ;The buttons:
  212.  
  213. spin =         [                $
  214.         [000B, 000B, 000B, 000B, 000B, 000B, 000B, 000B, 000B, 000B],            $
  215.         [000B, 000B, 000B, 000B, 000B, 000B, 000B, 000B, 000B, 000B],            $
  216.         [000B, 000B, 000B, 000B, 000B, 000B, 000B, 000B, 000B, 000B],            $
  217.         [000B, 000B, 000B, 000B, 000B, 000B, 000B, 000B, 000B, 000B],            $
  218.         [000B, 000B, 000B, 000B, 000B, 000B, 000B, 000B, 000B, 000B],            $
  219.         [000B, 000B, 000B, 000B, 000B, 000B, 000B, 000B, 000B, 000B],            $
  220.         [000B, 000B, 000B, 000B, 000B, 000B, 000B, 000B, 000B, 000B],            $
  221.         [000B, 000B, 000B, 000B, 000B, 000B, 000B, 000B, 000B, 000B],            $
  222.         [000B, 000B, 000B, 000B, 000B, 000B, 000B, 048B, 000B, 000B],            $
  223.         [000B, 000B, 000B, 000B, 000B, 000B, 000B, 240B, 000B, 000B],            $
  224.         [000B, 000B, 000B, 000B, 000B, 000B, 000B, 240B, 003B, 000B],            $
  225.         [153B, 057B, 207B, 231B, 231B, 207B, 127B, 254B, 015B, 000B],            $
  226.         [153B, 057B, 207B, 231B, 231B, 207B, 127B, 254B, 063B, 000B],            $
  227.         [153B, 057B, 207B, 231B, 231B, 207B, 127B, 254B, 255B, 000B],            $
  228.         [153B, 057B, 207B, 231B, 231B, 207B, 127B, 254B, 255B, 003B],            $
  229.         [153B, 057B, 207B, 231B, 231B, 207B, 127B, 254B, 255B, 015B],            $
  230.         [153B, 057B, 207B, 231B, 231B, 207B, 127B, 254B, 255B, 031B],            $
  231.         [153B, 057B, 207B, 231B, 231B, 207B, 127B, 254B, 255B, 063B],            $
  232.         [153B, 057B, 207B, 231B, 231B, 207B, 127B, 254B, 255B, 063B],            $
  233.         [153B, 057B, 207B, 231B, 231B, 207B, 127B, 254B, 255B, 015B],            $
  234.         [153B, 057B, 207B, 231B, 231B, 207B, 127B, 254B, 255B, 003B],            $
  235.         [153B, 057B, 207B, 231B, 231B, 207B, 127B, 254B, 255B, 000B],            $
  236.         [153B, 057B, 207B, 231B, 231B, 207B, 127B, 254B, 063B, 000B],            $
  237.         [153B, 057B, 207B, 231B, 231B, 207B, 127B, 254B, 031B, 000B],            $
  238.         [153B, 057B, 207B, 231B, 231B, 207B, 127B, 254B, 007B, 000B],            $
  239.         [000B, 000B, 000B, 000B, 000B, 000B, 000B, 240B, 001B, 000B],            $
  240.         [000B, 000B, 000B, 000B, 000B, 000B, 000B, 112B, 000B, 000B],            $
  241.         [252B, 249B, 099B, 134B, 129B, 249B, 007B, 048B, 000B, 000B],            $
  242.         [252B, 249B, 103B, 142B, 129B, 249B, 007B, 000B, 000B, 000B],            $
  243.         [006B, 024B, 102B, 142B, 129B, 193B, 000B, 000B, 000B, 000B],            $
  244.         [006B, 024B, 102B, 158B, 129B, 193B, 000B, 000B, 000B, 000B],            $
  245.         [006B, 024B, 102B, 150B, 129B, 193B, 000B, 000B, 000B, 000B],            $
  246.         [124B, 248B, 099B, 182B, 129B, 193B, 000B, 000B, 000B, 000B],            $
  247.         [248B, 248B, 099B, 166B, 129B, 193B, 000B, 000B, 000B, 000B],            $
  248.         [128B, 025B, 096B, 230B, 129B, 193B, 000B, 000B, 000B, 000B],            $
  249.         [128B, 025B, 096B, 198B, 129B, 193B, 000B, 000B, 000B, 000B],            $
  250.         [128B, 025B, 096B, 198B, 129B, 193B, 000B, 000B, 000B, 000B],            $
  251.         [254B, 024B, 096B, 134B, 129B, 193B, 000B, 000B, 000B, 000B],            $
  252.         [254B, 024B, 096B, 134B, 129B, 193B, 000B, 000B, 000B, 000B],            $
  253.         [000B, 000B, 000B, 000B, 000B, 000B, 000B, 000B, 000B, 000B]            $
  254.         ]
  255.  
  256.  
  257.  
  258. dne = WIDGET_BUTTON(lpad, VALUE = 'Done', UVALUE = 'DONE')
  259.  
  260. ; Make the cool bitmap SPIN IT button if Motif, if Open Look, don't bother:
  261.  
  262. VERSION    = WIDGET_INFO(/VERSION)
  263. IF (VERSION.STYLE EQ 'OPEN LOOK') THEN $
  264. cna = WIDGET_BUTTON(lpad, VALUE = 'Spin World', UVALUE = 'CREATE') $
  265. ELSE $
  266. cna = WIDGET_BUTTON(lpad, VALUE = spin, UVALUE = 'CREATE')
  267.  
  268. help = WIDGET_BUTTON(lpad, VALUE = 'Help', UVALUE = 'HELP')
  269.  
  270.  
  271. ;The text for the exclusive projection buttons:
  272. names = ['Azimuthal', 'Cylindrical', 'Gnomonic', 'Lambert', $
  273.         'Mercator', 'Mollweide', 'Orthographic', 'Sinusoidal', $
  274.         'Stereographic']
  275.  
  276. ;Make the exclusive projection list. Turn release events off:
  277. XMENU, names, lcol, /EXCLUSIVE, /FRAME, $
  278.         TITLE = 'Map Projection', BUTTONS = projection, /NO_RELEASE
  279.  
  280. ;This is the two-button 'toggle' switch for continent drawing:
  281. conbase = WIDGET_BASE(lcol, /COLUMN, /FRAME, /EXCLUSIVE)
  282. drawcon = WIDGET_BUTTON(conbase, VALUE='Draw Continents', UVALUE='DRAWCON',$
  283.             /NO_RELEASE)
  284. nocon = WIDGET_BUTTON(conbase, VALUE='No Continents', UVALUE='NOCON',$
  285.               /NO_RELEASE)
  286.  
  287. ;This is the two-button 'toggle' switch for grid drawing:
  288. gridbase = WIDGET_BASE(lcol, /COLUMN, /FRAME, /EXCLUSIVE)
  289. drawgrid = WIDGET_BUTTON(gridbase, VALUE='Draw Grid', UVALUE='DRAWGRID',$
  290.              /NO_RELEASE)
  291. nogrid = WIDGET_BUTTON(gridbase, VALUE='No Grid', UVALUE='NOGRID',$
  292.                /NO_RELEASE)
  293.  
  294. ;This is the two-button 'toggle' switch for bilinear interpolation:
  295. bilinbase = WIDGET_BASE(lcol, /COLUMN, /FRAME, /EXCLUSIVE)
  296. bilinear = WIDGET_BUTTON(bilinbase, VALUE='Bilinear Interpolation', $
  297.              UVALUE='BILINEAR', /NO_RELEASE)
  298. nointerp = WIDGET_BUTTON(bilinbase, VALUE='No Interpolation', $
  299.              UVALUE='NOINTERP', /NO_RELEASE)
  300.  
  301.  
  302. ;MIDDLE COLUMN HAS LOTS OF STUFF
  303.  
  304. ;The 'Info about Image' fields:
  305. l1 = WIDGET_LABEL(mcol, VALUE='Information about Image:')
  306. w1 = WIDGET_BASE(mcol, /ROW)
  307. w2 = WIDGET_BASE(mcol, /ROW)
  308. w3 = WIDGET_BASE(mcol, /ROW)
  309. w4 = WIDGET_BASE(mcol, /ROW)
  310.  
  311. w11 = WIDGET_LABEL(w1, VALUE = 'Min Longitude')
  312. minlon = WIDGET_TEXT(w1, XSIZE=6, YSIZE=1, /EDITABLE, VALUE='-180',$
  313.              UVALUE = 'minlong')
  314.  
  315. w21 = WIDGET_LABEL(w2, VALUE = 'Max Longitude')
  316. maxlon = WIDGET_TEXT(w2, XSIZE=6, YSIZE=1, /EDITABLE, VALUE='180',$
  317.              UVALUE = 'maxlong')
  318.  
  319. w31 = WIDGET_LABEL(w3, VALUE = 'Min Latitude ')
  320. minlat = WIDGET_TEXT(w3, XSIZE=6, YSIZE=1, /EDITABLE, VALUE='-90',$
  321.              UVALUE = 'minlatit')
  322.  
  323. w41 = WIDGET_LABEL(w4, VALUE = 'Max Latitude ')
  324. maxlat = WIDGET_TEXT(w4, XSIZE=6, YSIZE=1, /EDITABLE, VALUE='90', $
  325.              UVALUE = 'maxlatit')
  326.  
  327. ;The Longitude and Latitude Sampling sliders:
  328. mcol2 = WIDGET_BASE(mcol, /FRAME, /COLUMN)
  329. lonsamp = WIDGET_SLIDER(mcol2, TITLE = 'Longitude Sampling', MINIMUM=0, $
  330.             MAXIMUM=imsize[1], VALUE = imsize[1]/5 < 32, $
  331.             UVALUE='lonsamp', XSIZE = 192)
  332.  
  333. latsamp = WIDGET_SLIDER(mcol2, TITLE = 'Latitude Sampling', MINIMUM=0, $
  334.             MAXIMUM=imsize[2], VALUE = IMSIZE[2]/5 < 32, $
  335.             UVALUE='latsamp', XSIZE = 192)
  336.  
  337. ;The 'Latitude to be Centered' slider:
  338. viewlat = WIDGET_SLIDER(mcol2, TITLE = 'Latitude to be Centered', $
  339.                         MINIMUM = -90, MAXIMUM = 90, VALUE = 0, $
  340.             UVALUE = 'latslider', XSIZE = 192)
  341.  
  342. ;The 'Rotation of North' slider:
  343. rotangle = WIDGET_SLIDER(mcol2, TITLE = 'Rotation of North', $
  344.              MINIMUM = -90, MAXIMUM = 90, VALUE = 0, $
  345.              UVALUE = 'rotslider', XSIZE = 192)
  346.  
  347. ;The Continent and Grid color sliders:
  348. concol = WIDGET_SLIDER(mcol2, TITLE = 'Continent Color', $
  349.                          MINIMUM = 0, MAXIMUM = !D.N_COLORS-1, $
  350.              VALUE = !D.N_COLORS-1, $
  351.                          UVALUE = 'concolslider', XSIZE = 192)
  352.  
  353. gridcol = WIDGET_SLIDER(mcol2, TITLE = 'Grid Color', $
  354.                          MINIMUM = 0, MAXIMUM = !D.N_COLORS-1, $
  355.               VALUE = !D.N_COLORS-1, $
  356.                          UVALUE = 'gridcolslider', XSIZE = 192)
  357.  
  358.  
  359. ;RIGHT COLUMN HAS SLIDER AND BUTTONS
  360.  
  361. ;The 'Animation Window Size' fields:
  362. winbase =  WIDGET_BASE(rcol, /COLUMN, /FRAME)
  363. wintitle = WIDGET_LABEL(winbase, VALUE='Animation Window Size:')
  364. w5 = WIDGET_BASE(winbase, /ROW)
  365.  
  366. w15 = WIDGET_LABEL(w5, VALUE = 'Width')
  367. width = WIDGET_TEXT(w5, XSIZE=3, YSIZE=1, /EDITABLE, VALUE='400', $
  368.                     UVALUE = 'setwidth')
  369.  
  370. w35 = WIDGET_LABEL(w5, VALUE = 'Height')
  371. height = WIDGET_TEXT(w5, XSIZE=3, YSIZE=1, /EDITABLE, VALUE='400', $
  372.                      UVALUE = 'setheight')
  373.  
  374. ;The 'Number of Frames' slider:
  375. numframes = WIDGET_SLIDER(rcol, TITLE = 'Number of Frames', $
  376.                           MAXIMUM=100, MINIMUM=2, VALUE=10, /FRAME, $
  377.                UVALUE = 'frameslider')
  378.  
  379. ;The 'Messages' window:
  380. instruct = WIDGET_LABEL(rcol, VALUE='Messages:')
  381. message = WIDGET_TEXT(rcol, XSIZE=28, YSIZE=2, $
  382.               UVALUE='createtext', FRAME=2)
  383.  
  384. ;Create some default messages:
  385. adjust=['Adjust parameters and/or','select SPIN button.']
  386. display=['Displaying Animation Tool']
  387.  
  388. ;REALIZE THE WIDGETS:
  389. WIDGET_CONTROL, base, /REALIZE
  390.  
  391. ;Set the default to be ORTHOGRAPHIC
  392. theproj = 6
  393. WIDGET_CONTROL, projection[theproj], /SET_BUTTON
  394.  
  395. ;Put the 'Adjust values...' message in the message window:
  396. WIDGET_CONTROL, message, SET_VALUE = adjust
  397.  
  398. ;Set Grid drawing to ON:
  399. WIDGET_CONTROL, drawgrid, /SET_BUTTON
  400. grid = 1
  401.  
  402. ;Set Continent drawing to ON:
  403. WIDGET_CONTROL, drawcon, /SET_BUTTON
  404. con = 1
  405.  
  406. ;Set Interpolation to OFF:
  407. WIDGET_CONTROL, nointerp, /SET_BUTTON
  408. bilin = 0
  409.  
  410. ;HAND THINGS OFF TO THE X MANAGER:
  411. XMANAGER, 'worldrot', base, GROUP_LEADER = GROUP, /NO_BLOCK
  412.  
  413. END
  414.